package cade;

import java.util.Random;

import evaluator.FitnessFunction;

public class Utils {
	public static final Random rand = new Random();
	
	public static final int maxGeracoes = 50;
	public static final int tamanhoPopulacao = 30;

	public static final double taxaCruzamento = 0.8;//1;
	public static final double fator = 0.9;//0.5;

	public static int qtdVariaveis = 22;
	
	/************ Crencas ************/
	public static final int qtdSituacional = 2;
	public static int qtdAceitos = tamanhoPopulacao/2;

	/************ Crencas ************/
	
	public static double[] limiteSuperior = new double[qtdVariaveis];
	public static double[] limiteInferior = new double[qtdVariaveis];
	static{
		//gearbox/gear 2 ~ 6
		limiteInferior[0] = 0;
		limiteSuperior[0] = 5;
		limiteInferior[1] = 0;
		limiteSuperior[1] = 5;
		limiteInferior[2] = 0;
		limiteSuperior[2] = 5;
		limiteInferior[3] = 0;
		limiteSuperior[3] = 5;
		limiteInferior[4] = 0;
		limiteSuperior[4] = 5;
		
		//Rear Wing
		limiteInferior[5] = 0;
		limiteSuperior[5] = 18;
		//Front Wing
		limiteInferior[6] = 0;
		limiteSuperior[6] = 12;
		
		//Brake System
		limiteInferior[7] = 0.3;
		limiteSuperior[7] = 0.7;
		limiteInferior[8] = 100;
		limiteSuperior[8] = 150000;

		//Front anti roll bar
		limiteInferior[9] = 0;
		limiteSuperior[9] = 5000;
		//Rear anti roll bar
		limiteInferior[10] = 0;
		limiteSuperior[10] = 5000;
		
		limiteInferior[11] = 100;
		limiteSuperior[11] = 300;
		
		limiteInferior[12] = -5;
		limiteSuperior[12] = 5;
		
		limiteInferior[13] = -5;
		limiteSuperior[13] = -3;
		
		limiteInferior[14] = 100;
		limiteSuperior[14] = 300;
		
		limiteInferior[15] = -5;
		limiteSuperior[15] = -2;
		
		limiteInferior[16] = 0;
		limiteSuperior[16] = 10000;
		
		limiteInferior[17] = 0;
		limiteSuperior[17] = 0.2;
		
		limiteInferior[18] = 0;
		limiteSuperior[18] = 10000;
		
		limiteInferior[19] = 0;
		limiteSuperior[19] = 0.2;
		
		limiteInferior[20] = 100;
		limiteSuperior[20] = 380;
		
		limiteInferior[21] = 100;
		limiteSuperior[21] = 380;
		
		for(int i = 0; i < 22; i++){
			limiteInferior[i] = 0;
			limiteSuperior[i] = 1;
		}
	}
	public static final FitnessFunction funcao = null;
	
	/************ Chance da Influencia dos componentes ************/
	public static final double usarEvolDifPadrao = 0.2;
	public static final double usarComponenteSituacional= 0.5;
	public static final double ajustarDominioUsandoNormativo = 0.2;
	//usarComponenteNormativo = 1 - (taxaEvolDifPadrao + usarComponenteSituacional)
	
	
	public static double getRandomDouble(double limiteInferior, double limiteSuperior){
		return (limiteSuperior - limiteInferior) * rand.nextDouble() + limiteInferior;
	}
	
	public static int getRandomInt(int limiteInferior, int limiteSuperior){
		return limiteInferior + (int)(rand.nextDouble() * ((limiteSuperior - limiteInferior) + 1));
	}
	
	public static double getRandomPercentual(){
		return rand.nextDouble();
	}
	
	
	
	public static void copiarIndividuo(Individuo fonte, Individuo destino){
		for(int i = 0; i < qtdVariaveis; i++){
			destino.x[i] = fonte.x[i];
		}
		
		destino.funcao = fonte.funcao;
		destino.f = fonte.f;
	}
}
